package sun.circleprogerss;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.johnsun.mytestapp.R;

import java.util.ArrayList;

public class TestProgress extends Activity {
    private int progress = 0;
    private RoundProgressBar mRoundProgressBar;
    private Button button;
    private GridView gridView;
    private  Myadapter myadapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_progress);

        mRoundProgressBar=(RoundProgressBar) findViewById(R.id.roundProgressBar3);
        button= (Button) findViewById(R.id.button3);
        gridView= (GridView) findViewById(R.id.gridView);
        myadapter=new Myadapter(this);
        gridView.setAdapter(myadapter);
         NetProgressData netProgressData =new NetProgressData();
        ArrayList<NetProgressData> myNetList=new ArrayList<>();
        myNetList.add(netProgressData);
        myadapter.setList(myNetList);

        netProgressData.setLessonSyninfo(new LessonSyncInfo(new CustomLesson(),1));


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.out.println("点击事件");

                new Thread(new Runnable() {
                    @Override
                    public void run() {

                        while (progress<500){
                            progress+=3;
                            System.out.println(progress);
                            mRoundProgressBar.setProgress(progress);

                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }

                    }
                }).start();


            }
        });

    }
}

  class Myadapter extends BaseAdapter{


      private ArrayList<NetProgressData> list;

      private LayoutInflater inflater;
      private  int progress=0;
      private Context context;
      public Myadapter(Context context){
          this.context=context;
          inflater=LayoutInflater.from(context);
      }


      @Override
      public int getCount() {
          return 20;
      }

      @Override
      public Object getItem(int position) {
          return null;
      }

      @Override
      public long getItemId(int position) {
          return 0;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
       final ViewHolder viewHolder;
          if (convertView==null){
              viewHolder=new ViewHolder();
              convertView=inflater.inflate(R.layout.grid_item_custom_lesson_select,null);
              AbsListView.LayoutParams params = new AbsListView.LayoutParams(456,316);
              convertView.setLayoutParams(params);
              viewHolder.mprogess=(RoundProgressBar)convertView.findViewById(R.id.roundProgressBar3);



              convertView.setTag(viewHolder);

          }
          else {
              viewHolder= (ViewHolder) convertView.getTag();
          }

           NetProgressData netProgressData= list.get(position);
           viewHolder.mprogess.setProgress((int) netProgressData.getUplodProgressNum());



          return convertView;
      }

      public void setList(ArrayList<NetProgressData> list) {
          this.list = list;
      }


      class ViewHolder{
          TextView tv_customname;
          TextView tv_custominfo;
          TextView tv_customlevel;
          ImageView thumbnailIcon;
          ImageView isSelectedIcon;
          ImageView upDownLoadIcon;
          ImageView typeCustom_iv;
          RoundProgressBar mprogess;
      }


  }


